//
//  DBHelper2.m
//  WeChatTool
//
//  Created by TerryChe on 2018/1/25.
//  Copyright © 2018年 TerryChe. All rights reserved.
//

#import "DBHelper2.h"
#import "WCTConfig.h"

@implementation FMDatabase (Helper)

//#pragma 同步查询
/**
 *  同步执行一个查询
 *
 *  @param sql 查询SQL
 *
 *  @return 返回查询结果，结果为NSArray，Array里面为NSDictionary
 */
-(NSArray*)syncExecuteQuery:(NSString*)sql {
    NSMutableArray<NSDictionary *> *results = [NSMutableArray arrayWithCapacity:[WCTConfig sharedInstance].batchCount];
    
    FMResultSet *rs = [self executeQuery:sql];
    while (rs.next) {
        [results addObject:rs.resultDictionary];
    }

    if (rs) {
        [rs close];
    }
    
    NSError *error = [self lastError];
    if (error && error.code !=0 && error.code != 100) {
        [NSException raise:@"db Error" format:@"DB Error:%@",error.description];
    }

    return results;
}

@end
